-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flake8-bugbear
] Allow tuples of exceptions (B030
)
#10437
[flake8-bugbear
] Allow tuples of exceptions (B030
)
#10437
Conversation
|
Oh, we seem to have worked on it at the same time, I just wanted to open a PR fixing this as well 😅 I checked out your PR and checked it against my tests, and it doesn't seem to be complete with the nesting. try:
...
except (ValueError, *(RuntimeError, TypeError), *((ArithmeticError,) + (EOFError,))):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B030
... This is flagged as error, although this is valid. |
Ok I can close this in favor of yours. |
@autinerd actually let me know if you think I should fix that bug and continue, or just close this! Sorry about the confusion - I meant to say that I'd work on this issue. |
I think that would be a good idea if you work on it, as my knowledge in the Ruff codebase (and Rust in general) is not really good. My solution was to handle it recursively, maybe it is possible to do it iteratively as well. |
try: | ||
pass | ||
except (ValueError, *(RuntimeError, TypeError), *((ArithmeticError,) + (EOFError,))): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@autinerd added this test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Thanks.
Expr::BinOp(ast::ExprBinOp { | ||
left, | ||
right, | ||
op: Operator::Add, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gated these to Operator::Add
.
flake8-bugbear
] Allow tuples of exceptions (B030
)
No need for preview here since it's a bug fix. |
Fixes #10426
Summary
Fix rule B030 giving a false positive with Tuple operations like
+
.Playground
Reviewer notes
This is a little more convoluted than I was expecting -- because we can have valid nested Tuples with operations done on them, the flattening logic has become a bit more complex.
Shall I guard this behind --preview?
Test Plan
Unit tested.